#include "net.hpp"
#include <thread>


void Onmessage(const BaseConnection::ptr &conn, BaseMessage::ptr &msg)
{
    //得到服务端响应，打印消息
    std::string r = msg->serialize();
    std::cout << r << std::endl;
}


int main()
{

    auto client = ClientFactory::ClientCreate("127.0.0.1",8888);

    client->SetMessageCallback(Onmessage);

    client->connect();

    auto rpc_req = MessageFactory::Createmsg<RpcRequest>();

    rpc_req->Setid("10");
    rpc_req->SetMtype(ns_fields::Mtype::RPC_REQ);
    rpc_req->SetMethod("add");

    Json::Value v;
    v["num1"] = 11;
    v["num2"] = 22;
    rpc_req->SetParameters(v);

    client->send(rpc_req);

    std::this_thread::sleep_for(std::chrono::seconds(10));

    client->shutdown();

}